package com.sylli.oeuf.server.db;

import com.sylli.oeuf.server.db.sql.MySQLAccount;
import com.sylli.oeuf.server.db.sql.MySQLCharacterGeneralInfoProvider;
import com.sylli.oeuf.server.db.sql.MySQLCharacterPostData;
import com.sylli.oeuf.server.db.sql.MySQLMapBlock;
import com.sylli.oeuf.server.db.sql.MySQLMapMonster;
import com.sylli.oeuf.server.db.sql.MySQLMonster;
import com.sylli.oeuf.server.exception.BasedException;
import com.sylli.oeuf.server.exception.ExceptionCause;
import com.sylli.oeuf.server.object.transferable.AccountTO;
import com.sylli.oeuf.server.object.transferable.CharacterGeneralInfoTO;
import com.sylli.oeuf.server.object.transferable.CharacterPostDataTO;
import com.sylli.oeuf.server.object.transferable.MapBlockTO;
import com.sylli.oeuf.server.object.transferable.MapMonsterTO;
import com.sylli.oeuf.server.object.transferable.MonsterTO;

public class DatabaseProviderBundle {
	
	public static DatabaseProviderBundle getInstance() {
		if (instance == null) {
			synchronized (DatabaseProviderBundle.class) {
				if (instance == null) {
					instance = new DatabaseProviderBundle();
				}
			}
		}
		return instance;
	}
	
	private static DatabaseProviderBundle instance = null;

	private DatabaseProviderBundle() {
		
	}
	
	/* modular provider plug-in */
	/* to disable cache, just assign cache as null */

	public final AbstractProvider<AccountTO> account = 
		new MySQLAccount();
	
	public final AbstractProvider<CharacterGeneralInfoTO> charGenInfo = 
		new MySQLCharacterGeneralInfoProvider();
	
	public final AbstractProvider<MapMonsterTO> mapMonster =
		new MySQLMapMonster();
	
	public final AbstractProvider<MapBlockTO> mapBlock = 
		new MySQLMapBlock();
	
	public final AbstractProvider<CharacterPostDataTO> charPostData =
		new MySQLCharacterPostData();
	
	public final AbstractProvider<MonsterTO> monster =
		new MySQLMonster();
	
	// Utils
	/**
	 * Check wheter the long[] array of id is sized with 1 or 0
	 * 
	 * @return false if result size is 0
	 * @return true if result size is 1
	 * @throws BasedException
	 */
	public final boolean assertZeroOrOneResultSize(long[] allresults) throws BasedException {
		if (allresults == null) {
			throw new BasedException(ExceptionCause.AssertionFail, "null array.");
		} else if (allresults.length == 0) {
			return false;
		} else if (allresults.length == 1) {
			return true;
		}
		throw new BasedException(ExceptionCause.AssertionFail, "size is not 0 nor 1 [size=" + allresults.length + "]");
	}
	
}
